﻿using DevExpress.XtraEditors;
using Shopfloormanagement;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;


namespace Shopfloormanagement
{
    public partial class Step6 : DevExpress.XtraEditors.XtraForm
    {
        public Step6()
        {
            InitializeComponent();
        }
        int step1;
        int step2;
        int step3;
        int step4;
        int step5;
        int step6;
        int step7;
        int step8;
        int step9;
        //给5why按钮赋bool
        bool btn1 ;
        bool btn2 ;
        private void Word()//加载进度下方文字
        {
            lblStep1.Text = "Problem\nStatement";
            lblStep2.Text = "Problem\nDescription";
            lblStep3.Text = "Interim\nContainment\nactions";
            lblStep4.Text = "Identify\nPossible\nCauses";
            lblStep5.Text = "Test all\nPossible\nCauses";
            lblStep6.Text = "Verify\nPotential\nRoot Cause";
            lblStep7.Text = "Confirmed\nRoot Cause";
            lblStep8.Text = "Permanent\nCorrective\nActions";
            lblStep9.Text = "Further\nActivities";

        }
        private void LoadA3list()//获取上方图片状态
        {

            DataTable A3list = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_List", $"ID = '{rootcause.A3number}'");

            step1 = (int)A3list.Rows[0][6];
            step2 = (int)A3list.Rows[0][7];
            step3 = (int)A3list.Rows[0][8];
            step4 = (int)A3list.Rows[0][9];
            step5 = (int)A3list.Rows[0][10];
            step6 = (int)A3list.Rows[0][11];
            step7 = (int)A3list.Rows[0][12];
            step8 = (int)A3list.Rows[0][13];
            step9 = (int)A3list.Rows[0][14];
            LoadPicture(step1, step2, step3, step4, step5, step6, step7, step8, step9);
        }
        private void LoadPicture(int condition1, int condition2, int condition3, int condition4, int condition5, int condition6, int condition7, int condition8, int condition9)
        {
            switch (condition1)
            {
                case 1:
                    picstep1.Image = Properties.Resources.G1;
                    break;
                case 2:
                    picstep1.Image = Properties.Resources.B1;
                    break;
                case 3:
                    picstep1.Image = Properties.Resources.R1;
                    break;
                case 4:
                    picstep1.Image = Properties.Resources.H1;
                    break;
                default:
                    picstep1.Image = null;
                    break;
            }
            switch (condition2)
            {
                case 1:
                    picstep2.Image = Properties.Resources.G2;
                    break;
                case 2:
                    picstep2.Image = Properties.Resources.B2;
                    break;
                case 3:
                    picstep2.Image = Properties.Resources.R2;
                    break;
                case 4:
                    picstep2.Image = Properties.Resources.H2;
                    break;
                default:
                    picstep2.Image = null;
                    break;
            }
            switch (condition3)
            {
                case 1:
                    picstep3.Image = Properties.Resources.G3;
                    break;
                case 2:
                    picstep3.Image = Properties.Resources.B3;
                    break;
                case 3:
                    picstep3.Image = Properties.Resources.R3;
                    break;
                case 4:
                    picstep3.Image = Properties.Resources.H3;
                    break;
                default:
                    picstep3.Image = null;
                    break;
            }
            switch (condition4)
            {
                case 1:
                    picstep4.Image = Properties.Resources.G4;
                    break;
                case 2:
                    picstep4.Image = Properties.Resources.B4;
                    break;
                case 3:
                    picstep4.Image = Properties.Resources.R4;
                    break;
                case 4:
                    picstep4.Image = Properties.Resources.H4;
                    break;
                default:
                    picstep4.Image = null;
                    break;
            }
            switch (condition5)
            {
                case 1:
                    picstep5.Image = Properties.Resources.G5;
                    break;
                case 2:
                    picstep5.Image = Properties.Resources.B5;
                    break;
                case 3:
                    picstep5.Image = Properties.Resources.R5;
                    break;
                case 4:
                    picstep5.Image = Properties.Resources.H5;
                    break;
                default:
                    picstep5.Image = null;
                    break;
            }
            switch (condition6)
            {
                case 1:
                    picstep6.Image = Properties.Resources.G6;
                    break;
                case 2:
                    picstep6.Image = Properties.Resources.B6;
                    break;
                case 3:
                    picstep6.Image = Properties.Resources.R6;
                    break;
                case 4:
                    picstep6.Image = Properties.Resources.H6;
                    break;
                default:
                    picstep6.Image = null;
                    break;
            }
            switch (condition7)
            {
                case 1:
                    picstep7.Image = Properties.Resources.G7;
                    break;
                case 2:
                    picstep7.Image = Properties.Resources.B7;
                    break;
                case 3:
                    picstep7.Image = Properties.Resources.R7;
                    break;
                case 4:
                    picstep7.Image = Properties.Resources.H7;
                    break;
                default:
                    picstep7.Image = null;
                    break;
            }
            switch (condition8)
            {
                case 1:
                    picstep8.Image = Properties.Resources.G8;
                    break;
                case 2:
                    picstep8.Image = Properties.Resources.B8;
                    break;
                case 3:
                    picstep8.Image = Properties.Resources.R8;
                    break;
                case 4:
                    picstep8.Image = Properties.Resources.H8;
                    break;
                default:
                    picstep8.Image = null;
                    break;
            }
            switch (condition9)
            {
                case 1:
                    picstep9.Image = Properties.Resources.G9;
                    break;
                case 2:
                    picstep9.Image = Properties.Resources.B9;
                    break;
                case 3:
                    picstep9.Image = Properties.Resources.R9;
                    break;
                case 4:
                    picstep9.Image = Properties.Resources.H9;
                    break;
                default:
                    picstep9.Image = null;
                    break;
            }

        }
        private void LoadA3step6()//加载信息及判断是否过期
        {
            //获取选中A3的数据
            DataTable A3Step6 = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_Step6", $"A3ReportNumberID = '{rootcause.A3number}'");
            if (A3Step6.Rows.Count == 0) return; // 如果没有数据，直接返回

            DataRow row = A3Step6.Rows[0]; // 取第 0 行数据

            //判断有几个Action,显示对应数量的控件
            string action6 = A3Step6.Rows[0][16].ToString();
            string action7 = A3Step6.Rows[0][17].ToString();
            string action8 = A3Step6.Rows[0][18].ToString();
            string action9 = A3Step6.Rows[0][19].ToString();

            if (action9 != "")
            {
                lbl6.Visible = false;
                pal6.Visible = true;
                pal7.Visible = true;
                pal8.Visible = true;
                pal9.Visible = true;
            }
            if (action9 == "" && action8 != "")
            {
                lbl6.Visible = false;
                pal6.Visible = true;
                pal7.Visible = true;
                pal8.Visible = true;
                pal9.Visible = false;
            }
            if (action9 == "" && action8 == "" && action7 != "")
            {
                lbl6.Visible = false;
                pal6.Visible = true;
                pal7.Visible = true;
                pal8.Visible = false;
                pal9.Visible = false;
            }
            if (action9 == "" && action8 == "" && action7 == "" && action6 != "")
            {
                lbl6.Visible = false;
                pal6.Visible = true;
                pal7.Visible = false;
                pal8.Visible = false;
                pal9.Visible = false;
            }
            // 加载Cause
            for (int i = 1; i <= 9; i++)
            {
                string columnName = $"PossibleCauses{i}";

                // 确保列存在
                if (!A3Step6.Columns.Contains(columnName)) continue;

                // 获取 ComboBox 控件
                Control[] controls = this.Controls.Find($"cob{i}", true);
                if (controls.Length > 0 && controls[0] is DevExpress.XtraEditors.ComboBoxEdit combobox)
                {
                    // 赋值，忽略 NULL
                    combobox.Text = row[columnName] != DBNull.Value ? row[columnName].ToString() : string.Empty;
                }
            }
            // 加载Action
            for (int i = 1; i <= 9; i++)
            {
                string columnName = $"Action{i}";

                // 确保列存在
                if (!A3Step6.Columns.Contains(columnName)) continue;

                // 获取 TextEdit 控件
                Control[] controls = this.Controls.Find($"txtaction{i}", true);
                if (controls.Length > 0 && controls[0] is DevExpress.XtraEditors.TextEdit textEdit)
                {
                    // 赋值，忽略 NULL
                    textEdit.Text = row[columnName] != DBNull.Value ? row[columnName].ToString() : string.Empty;
                }
            }
            // 加载Who
            for (int i = 1; i <= 9; i++)
            {
                string columnName = $"Who{i}";

                // 确保列存在
                if (!A3Step6.Columns.Contains(columnName)) continue;

                // 获取 TextEdit 控件
                Control[] controls = this.Controls.Find($"txtwho{i}", true);
                if (controls.Length > 0 && controls[0] is DevExpress.XtraEditors.TextEdit textEdit)
                {
                    // 赋值，忽略 NULL
                    textEdit.Text = row[columnName] != DBNull.Value ? row[columnName].ToString() : string.Empty;
                }
            }
            // 加载When
            for (int i = 1; i <= 9; i++)
            {
                string columnName = $"When{i}";

                // 确保列存在
                if (!A3Step6.Columns.Contains(columnName)) continue;

                // 获取 DateEdit 控件
                Control[] controls = this.Controls.Find($"dtwhen{i}", true);
                if (controls.Length > 0 && controls[0] is DevExpress.XtraEditors.DateEdit dateEdit)
                {
                    // 赋值，忽略 NULL
                    if (row[columnName] != DBNull.Value)
                    {
                        dateEdit.DateTime = Convert.ToDateTime(row[columnName]);
                    }
                    else
                    {
                        dateEdit.EditValue = null; // 清空 DateEdit，避免显示默认日期
                    }
                }
            }
            // 加载Direct
            for (int i = 1; i <= 9; i++)
            {
                string columnName = $"Direct{i}";  // 列名
                // 确保列存在
                if (!A3Step6.Columns.Contains(columnName)) continue;

                // 获取 CheckEdit 控件
                Control[] controls = this.Controls.Find($"ckdirect{i}", true);
                if (controls.Length > 0 && controls[0] is DevExpress.XtraEditors.CheckEdit checkEdit)
                {
                    // 将 bit (bool) 赋值给 CheckEdit
                    checkEdit.Checked = row[columnName] != DBNull.Value && Convert.ToBoolean(row[columnName]);
                }
            }
            // 加载NOT
            for (int i = 1; i <= 9; i++)
            {
                string columnName = $"Not{i}";  // 列名
                // 确保列存在
                if (!A3Step6.Columns.Contains(columnName)) continue;

                // 获取 CheckEdit 控件
                Control[] controls = this.Controls.Find($"cknot{i}", true);
                if (controls.Length > 0 && controls[0] is DevExpress.XtraEditors.CheckEdit checkEdit)
                {
                    // 将 bit (bool) 赋值给 CheckEdit
                    checkEdit.Checked = row[columnName] != DBNull.Value && Convert.ToBoolean(row[columnName]);
                }
            }
            //措施超期文字变成红色
            for (int i = 1; i <= 9; i++)
            {
                TextEdit txtAction = (TextEdit)this.Controls.Find($"txtaction{i}", true).FirstOrDefault();
                CheckEdit ckdirect = (CheckEdit)this.Controls.Find($"ckdirect{i}", true).FirstOrDefault();
                CheckEdit cknot = (CheckEdit)this.Controls.Find($"cknot{i}", true).FirstOrDefault();
                DateEdit dtWhen = (DateEdit)this.Controls.Find($"dtwhen{i}", true).FirstOrDefault();

                if (txtAction != null && ckdirect != null && cknot != null && dtWhen != null)
                {
                    if (!string.IsNullOrWhiteSpace(txtAction.Text)) // txtactionX 有内容
                    {
                        if (!(ckdirect.Checked || cknot.Checked)) // ckyesX 和 cknoX 都未选中
                        {
                            if (dtWhen.EditValue != null && dtWhen.DateTime < DateTime.Now) // 时间小于当前时间
                            {
                                dtWhen.ForeColor = Color.Red;
                            }
                            else
                            {
                                dtWhen.ForeColor = Color.Black;
                            }
                        }
                    }
                }
            }

            //5Why加载
            DataTable A3Step6_5Why = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_Step6_5Why", $"A3ReportNumberID = '{rootcause.A3number}'");
            if (A3Step6_5Why.Rows.Count == 0) return; // 如果没有数据，直接返回
            DataRow row_5Why = A3Step6_5Why.Rows[0]; // 取第 0 行数据
            string direct1 = A3Step6_5Why.Rows[0][2].ToString();
            string direct2 = A3Step6_5Why.Rows[0][3].ToString();
            bool root_cause1 = (bool)A3Step6_5Why.Rows[0][24];
            bool root_cause2 = (bool)A3Step6_5Why.Rows[0][25];
            //判断有几个直接原因显示几个信息
            if (direct2 != "")
            {
                lbl22.Visible = false;
                pal22.Visible = true;
            }

            // 加载Direct Cause
            for (int i = 1; i <= 2; i++)
            {
                string columnName = $"DirectCause{i}";

                // 确保列存在
                if (!A3Step6_5Why.Columns.Contains(columnName)) continue;

                // 获取 ComboBox 控件
                Control[] controls = this.Controls.Find($"cob2{i}", true);
                if (controls.Length > 0 && controls[0] is DevExpress.XtraEditors.ComboBoxEdit combobox)
                {
                    // 赋值，忽略 NULL
                    combobox.Text = row_5Why[columnName] != DBNull.Value ? row_5Why[columnName].ToString() : string.Empty;
                }
            }
            // 加载5Why1组
            for (int i = 1; i <= 5; i++)
            {
                string columnName = $"Why1{i}";

                // 确保列存在
                if (!A3Step6_5Why.Columns.Contains(columnName)) continue;

                // 获取 TextEdit 控件
                Control[] controls = this.Controls.Find($"txtwhy1{i}", true);
                if (controls.Length > 0 && controls[0] is DevExpress.XtraEditors.TextEdit textEdit)
                {
                    // 赋值，忽略 NULL
                    textEdit.Text = row_5Why[columnName] != DBNull.Value ? row_5Why[columnName].ToString() : string.Empty;
                }
            }
            // 加载5Why2组
            for (int i = 1; i <= 5; i++)
            {
                string columnName = $"Why2{i}";

                // 确保列存在
                if (!A3Step6_5Why.Columns.Contains(columnName)) continue;

                // 获取 TextEdit 控件
                Control[] controls = this.Controls.Find($"txtwhy2{i}", true);
                if (controls.Length > 0 && controls[0] is DevExpress.XtraEditors.TextEdit textEdit)
                {
                    // 赋值，忽略 NULL
                    textEdit.Text = row_5Why[columnName] != DBNull.Value ? row_5Why[columnName].ToString() : string.Empty;
                }
            }
            // 加载5Because 1组
            for (int i = 1; i <= 5; i++)
            {
                string columnName = $"Because1{i}";

                // 确保列存在
                if (!A3Step6_5Why.Columns.Contains(columnName)) continue;

                // 获取 TextEdit 控件
                Control[] controls = this.Controls.Find($"txtbecause1{i}", true);
                if (controls.Length > 0 && controls[0] is DevExpress.XtraEditors.TextEdit textEdit)
                {
                    // 赋值，忽略 NULL
                    textEdit.Text = row_5Why[columnName] != DBNull.Value ? row_5Why[columnName].ToString() : string.Empty;
                }
            }
            // 加载5Because 2组
            for (int i = 1; i <= 5; i++)
            {
                string columnName = $"Because2{i}";

                // 确保列存在
                if (!A3Step6_5Why.Columns.Contains(columnName)) continue;

                // 获取 TextEdit 控件
                Control[] controls = this.Controls.Find($"txtbecause2{i}", true);
                if (controls.Length > 0 && controls[0] is DevExpress.XtraEditors.TextEdit textEdit)
                {
                    // 赋值，忽略 NULL
                    textEdit.Text = row_5Why[columnName] != DBNull.Value ? row_5Why[columnName].ToString() : string.Empty;
                }
            }
            //加载Root cause1
            if (root_cause1 == true)
            {
                btn1 = true;
                Rootcause1yes.Appearance.BackColor = Color.Green;
                Rootcause1no.Appearance.BackColor = Color.FromArgb(234, 234, 234);
            }
            else
            {
                btn1 = false;
                Rootcause1no.Appearance.BackColor = Color.Red;
                Rootcause1yes.Appearance.BackColor = Color.FromArgb(234, 234, 234);
            }
            //加载Root cause 2
            if (root_cause2 == true)
            {
                btn2 = true;
                Rootcause2yes.Appearance.BackColor = Color.Green;
                Rootcause2no.Appearance.BackColor = Color.FromArgb(234, 234, 234);
            }
            else
            {
                btn2 = false;
                Rootcause2no.Appearance.BackColor = Color.Red;
                Rootcause2yes.Appearance.BackColor = Color.FromArgb(234, 234, 234);
            }

            //获取选中A3Step1的数据(Duedate)
            DataTable A3Step1 = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_Step1", $"A3ReportNumberID = '{rootcause.A3number}'");
            //超期图片变红
            object dbTimeObj = A3Step1.Rows[0]["Duedate"];//获取数据库中的日期数据
            DateTime dbTime;
            if (dbTimeObj != DBNull.Value && DateTime.TryParse(dbTimeObj.ToString(), out dbTime))
            {
                if (dbTime < DateTime.Now)
                {
                    bool reslist = LSQL.SQL.Update(SystemInfo.SQL, "A3_List", "Step6 = 3", $"ID = '{rootcause.A3number}' and Step6 != 1");
                    //Load A3list 获得step3的值
                    DataTable A3listTemp = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_List", $"ID = '{rootcause.A3number}'");
                    //获取上方图片状态
                    step1 = (int)A3listTemp.Rows[0][6];
                    step2 = (int)A3listTemp.Rows[0][7];
                    step3 = (int)A3listTemp.Rows[0][8];
                    step4 = (int)A3listTemp.Rows[0][9];
                    step5 = (int)A3listTemp.Rows[0][10];
                    step6 = (int)A3listTemp.Rows[0][11];
                    step7 = (int)A3listTemp.Rows[0][12];
                    step8 = (int)A3listTemp.Rows[0][13];
                    step9 = (int)A3listTemp.Rows[0][14];
                    LoadPicture(step1, step2, step3, step4, step5, step6, step7, step8, step9);
                }
                else
                {
                    return;
                }
            }
        }
        private void LoadComboBoxDataFromTable()//加载Step5所有判断为√的根本原因
        {
            DataTable A3Step5 = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_Step5", $"A3ReportNumberID = '{rootcause.A3number}'");

            List<string> causeValues = new List<string>(); // 用于存储符合条件的 Cause 数据

            // 遍历 DataTable 的所有行
            foreach (DataRow row in A3Step5.Rows)
            {
                for (int i = 1; i <= 9; i++) // 遍历 Direct1 - Direct9
                {
                    string directColumn = $"Direct{i}";
                    string causeColumn = $"Cause{i}";

                    // 判断 Direct 列的值是否为 1
                    if (row.Table.Columns.Contains(directColumn) && row[directColumn] != DBNull.Value && Convert.ToInt32(row[directColumn]) == 1)
                    {
                        // 取出对应的 Cause 值
                        if (row.Table.Columns.Contains(causeColumn) && row[causeColumn] != DBNull.Value)
                        {
                            string causeValue = row[causeColumn].ToString();
                            if (!string.IsNullOrEmpty(causeValue) && !causeValues.Contains(causeValue)) // 避免重复添加
                            {
                                causeValues.Add(causeValue);
                            }
                        }
                    }
                }
            }

            // 将符合条件的 Cause 数据加载到所有 ComboBoxEdit 控件中
            foreach (var comboBox in new ComboBoxEdit[] { cob1, cob2, cob3, cob4, cob5, cob6, cob7, cob8, cob9 })
            {
                comboBox.Properties.Items.Clear(); // 清空原有数据
                comboBox.Properties.Items.AddRange(causeValues); // 添加新数据
            }
        }
        private void LoadComboBoxDataFromCheckEdit()
        {
            List<ComboBoxEdit> sourceComboBoxes = new List<ComboBoxEdit>
    {
        cob1, cob2, cob3, cob4, cob5, cob6, cob7, cob8, cob9
    };

            List<CheckEdit> sourceCheckEdits = new List<CheckEdit>
    {
        ckdirect1, ckdirect2, ckdirect3, ckdirect4, ckdirect5, ckdirect6, ckdirect7, ckdirect8, ckdirect9
    };

            List<ComboBoxEdit> targetComboBoxes = new List<ComboBoxEdit> { cob21, cob22 };

            // 收集所有 ckdirect 为 true 且 cob 有内容的值
            HashSet<string> selectedCauses = new HashSet<string>();
            for (int i = 0; i < 9; i++)
            {
                if (sourceCheckEdits[i].Checked && !string.IsNullOrWhiteSpace(sourceComboBoxes[i].Text))
                {
                    selectedCauses.Add(sourceComboBoxes[i].Text.Trim());
                }
            }

            // 重新设置 cob21 和 cob22 的下拉菜单
            foreach (var comboBox in targetComboBoxes)
            {
                string selected = comboBox.SelectedItem?.ToString();

                comboBox.Properties.Items.Clear(); // 先清空旧项
                comboBox.Properties.Items.AddRange(selectedCauses.ToArray()); // 添加所有新项

                // 如果之前有选中项仍在新列表中，保持选中
                if (!string.IsNullOrEmpty(selected) && selectedCauses.Contains(selected))
                {
                    comboBox.SelectedItem = selected;
                }
                else
                {
                    comboBox.SelectedItem = null; // 否则清空选中项
                }
            }
        }//为5why的ComboBoxEdit下拉菜单做选项
        private void BindComboBoxCheckEditEvents()
        {
            for (int i = 1; i <= 9; i++)
            {
                CheckEdit ck = this.Controls.Find($"ckdirect{i}", true).FirstOrDefault() as CheckEdit;
                ComboBoxEdit cob = this.Controls.Find($"cob{i}", true).FirstOrDefault() as ComboBoxEdit;

                if (ck != null)
                    ck.CheckedChanged += (s, e) => LoadComboBoxDataFromCheckEdit();
                if (cob != null)
                    cob.TextChanged += (s, e) => LoadComboBoxDataFromCheckEdit();
            }
        }//为5why的ComboBoxEdit下拉菜单做选项
        private void Step6_Load(object sender, EventArgs e)
        {
            
            Word();
            LoadA3list();
            LoadA3step6();
            LoadComboBoxDataFromTable();//加载Step5所有判断为√的根本原因
            CheckedChanged(sender, e);
            BindComboBoxCheckEditEvents();//为5why的ComboBoxEdit下拉菜单做选项
            LoadComboBoxDataFromCheckEdit(); //为5why的ComboBoxEdit下拉菜单做选项
            SetButtonEnable(this);//有Text调整不保存Next键不显示
            palstep1.BackColor = Color.FromArgb(146, 208, 80);
            palstep2.BackColor = Color.FromArgb(146, 208, 80);
            palstep3.BackColor = Color.FromArgb(146, 208, 80);
            palstep4.BackColor = Color.FromArgb(146, 208, 80);
            palstep5.BackColor = Color.FromArgb(146, 208, 80);
            palstep6.BackColor = Color.FromArgb(146, 208, 80);
            //将默认时间设置为空
            #region
            dtwhen1.Properties.NullDate = DateTime.MinValue; // 允许 NULL
            dtwhen1.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
            dtwhen2.Properties.NullDate = DateTime.MinValue; // 允许 NULL
            dtwhen2.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
            dtwhen3.Properties.NullDate = DateTime.MinValue; // 允许 NULL
            dtwhen3.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
            dtwhen4.Properties.NullDate = DateTime.MinValue; // 允许 NULL
            dtwhen4.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
            dtwhen5.Properties.NullDate = DateTime.MinValue; // 允许 NULL
            dtwhen5.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
            dtwhen6.Properties.NullDate = DateTime.MinValue; // 允许 NULL
            dtwhen6.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
            dtwhen7.Properties.NullDate = DateTime.MinValue; // 允许 NULL
            dtwhen7.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
            dtwhen8.Properties.NullDate = DateTime.MinValue; // 允许 NULL
            dtwhen8.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
            dtwhen9.Properties.NullDate = DateTime.MinValue; // 允许 NULL
            dtwhen9.Properties.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
            #endregion
        }
        private void SetButtonEnable(Control control)//检索所有TextEdit控件是否有变化，如有变化则不显示Next
        {

            if (control is TextEdit)
            {
                control.TextChanged += TextEditTextChange;
            }
            else
            {
                var controlCollection = control.Controls;
                foreach (Control subControl in controlCollection)
                {
                    SetButtonEnable(subControl);
                }
            }


        }
        private void CheckedChanged(object sender, EventArgs e)//检索所有CheckEdit控件是否有变化，如有变化则不显示Next
        {
            for (int i = 1; i <= 9; i++)
            {
                // 找到对应的控件
                var ckdirect = this.Controls.Find($"ckdirect{i}", true).FirstOrDefault() as CheckEdit;
                var cknot = this.Controls.Find($"cknot{i}", true).FirstOrDefault() as CheckEdit;

                // 绑定事件
                if (ckdirect != null) ckdirect.CheckedChanged += CheckEdit_CheckedChanged2;
                if (cknot != null) cknot.CheckedChanged += CheckEdit_CheckedChanged2;
            }
        }
        private void CheckEdit_CheckedChanged2(object sender, EventArgs e)
        {
            CheckEdit changedCheck = sender as CheckEdit;

            if (changedCheck != null)
            {
                TextEditTextChange(sender, e);
            }
        }//检索所有CheckEdit控件是否有变化，如有变化则不显示Next
        private void TextEditTextChange(object sender, EventArgs e)
        {

            btnNext.Visible = false;

        }//为SetButtonEnable制作的命令
        private void btnNext_Click(object sender, EventArgs e)
        {
            if (cob21.Text == "" && cob22.Text == "")
            {
                MessageBox.Show("5Why分析至少填写一个直接原因", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else if (cob21.Text != "" && cob22.Text == "")
            {
                if (txtwhy11.Text == "" || txtbecause11.Text == "" || txtwhy12.Text == "" || txtbecause12.Text == "")
                {
                    MessageBox.Show("主要直接原因分析至少填写两组Why-Because", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }
                else
                {
                    if (Rootcause1yes.Appearance.BackColor != Color.Green && Rootcause1no.Appearance.BackColor != Color.Red)
                    {
                        MessageBox.Show("请判断是否为直接原因", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        bool reslist = LSQL.SQL.Update(SystemInfo.SQL, "A3_List", "Step6 = 1", $"ID = '{rootcause.A3number}'");
                        if (reslist == true)
                        {
                            Step7 frm = new Step7();
                            frm.Show();
                            this.Hide();
                        }
                    }
                
                }

            }
            else if (cob21.Text == "" && cob22.Text != "")
            {
                if (txtwhy21.Text == "" || txtbecause21.Text == "" || txtwhy22.Text == "" || txtbecause22.Text == "")
                {

                    MessageBox.Show("次要直接原因分析至少填写两组Why-Because", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }
                else
                {
                    if (Rootcause2yes.Appearance.BackColor != Color.Green && Rootcause2no.Appearance.BackColor != Color.Red)
                    {
                        MessageBox.Show("请判断是否为直接原因", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        bool reslist = LSQL.SQL.Update(SystemInfo.SQL, "A3_List", "Step6 = 1", $"ID = '{rootcause.A3number}'");
                        if (reslist == true)
                        {
                            Step7 frm = new Step7();
                            frm.Show();
                            this.Hide();
                        }
                    }

                }
            }
            else if (cob21.Text != "" && cob22.Text != "")
            {
                if (txtwhy11.Text == "" || txtbecause11.Text == "" || txtwhy12.Text == "" || txtbecause12.Text == ""
                    || txtwhy21.Text == "" || txtbecause21.Text == "" || txtwhy22.Text == "" || txtbecause22.Text == "")
                {
                    MessageBox.Show("两组直接原因分析至少分别填写两组Why-Because", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }
                else
                {
                    bool reslist = LSQL.SQL.Update(SystemInfo.SQL, "A3_List", "Step6 = 1", $"ID = '{rootcause.A3number}'");
                    if (reslist == true)
                    {
                        Step7 frm = new Step7();
                        frm.Show();
                        this.Hide();
                    }
                }
            }
            
            
        }
        private void btnBack_Click(object sender, EventArgs e)
        {
            
            Step5fish frm = new Step5fish();
            frm.Show();
            this.Hide();

        }
        private void lbl6_Click(object sender, EventArgs e)
        {
            lbl6.Visible = false;
            pal6.Visible = true;
            pal7.Visible = true;
            pal8.Visible = true;
            
            
        }
        private void labelControl25_Click(object sender, EventArgs e)
        {
            lbl22.Visible = false;
            pal22.Visible = true;
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            DataTable A3Step6 = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_Step6", $"A3ReportNumberID = '{rootcause.A3number}'");
            DataTable A3Step6_5Why = LSQL.SQL.ReturnDataTable2(SystemInfo.SQL, "A3_Step6_5Why", $"A3ReportNumberID = '{rootcause.A3number}'");
            if (A3Step6.Rows.Count > 0 && A3Step6_5Why.Rows.Count > 0)
            {
                //Step6更新语句
                string content = $@"PossibleCauses1 = '{cob1.Text}',PossibleCauses2 = '{cob2.Text}',PossibleCauses3 = '{cob3.Text}',PossibleCauses4 = '{cob4.Text}',PossibleCauses5 = '{cob5.Text}',PossibleCauses6 = '{cob6.Text}',PossibleCauses7 = '{cob7.Text}',PossibleCauses8 = '{cob8.Text}',PossibleCauses9 = '{cob9.Text}',
                    Action1 = '{txtaction1.Text}',Action2 = '{txtaction2.Text}',Action3 = '{txtaction3.Text}',Action4 = '{txtaction4.Text}',Action5 = '{txtaction5.Text}',Action6 = '{txtaction6.Text}',Action7 = '{txtaction7.Text}',Action8 = '{txtaction8.Text}',Action9 = '{txtaction9.Text}',
                    Who1 = '{txtwho1.Text}',Who2 = '{txtwho2.Text}',Who3 = '{txtwho3.Text}',Who4 = '{txtwho4.Text}',Who5 = '{txtwho5.Text}',Who6 = '{txtwho6.Text}',Who7 = '{txtwho7.Text}',Who8 = '{txtwho8.Text}',Who9 = '{txtwho9.Text}',
                    When1 = '{dtwhen1.DateTime}',When2 = '{dtwhen2.DateTime}',When3 = '{dtwhen3.DateTime}',When4 = '{dtwhen4.DateTime}',When5 = '{dtwhen5.DateTime}',When6 = '{dtwhen6.DateTime}',When7 = '{dtwhen7.DateTime}',When8 = '{dtwhen8.DateTime}',When9 = '{dtwhen9.DateTime}',
                    Direct1 = '{ckdirect1.Checked}',Direct2 = '{ckdirect2.Checked}',Direct3 = '{ckdirect3.Checked}',Direct4 = '{ckdirect4.Checked}',Direct5 = '{ckdirect5.Checked}',Direct6 = '{ckdirect6.Checked}',Direct7 = '{ckdirect7.Checked}',Direct8 = '{ckdirect8.Checked}',Direct9 = '{ckdirect9.Checked}',
                    Not1 = '{cknot1.Checked}',Not2 = '{cknot2.Checked}',Not3 = '{cknot3.Checked}',Not4 = '{cknot4.Checked}',Not5 = '{cknot5.Checked}',Not6 = '{cknot6.Checked}',Not7 = '{cknot7.Checked}',Not8 = '{cknot8.Checked}',Not9 = '{cknot9.Checked}'";
                bool resstep6 = LSQL.SQL.Update(SystemInfo.SQL, "A3_Step6", content, $"A3ReportNumberID = '{rootcause.A3number}'");
                //5Why更新语句
                string content2 = $@"DirectCause1 = '{cob21.Text}',DirectCause2 = '{cob22.Text}',
                    Why11 = '{txtwhy11.Text}',Why12 = '{txtwhy12.Text}',Why13 = '{txtwhy13.Text}',Why14 = '{txtwhy14.Text}',Why15 = '{txtwhy15.Text}',
                    Why21 = '{txtwhy21.Text}',Why22 = '{txtwhy22.Text}',Why23 = '{txtwhy23.Text}',Why24 = '{txtwhy24.Text}',Why25 = '{txtwhy25.Text}',
                    Because11 = '{txtbecause11.Text}',Because12 = '{txtbecause12.Text}',Because13 = '{txtbecause13.Text}',Because14 = '{txtbecause14.Text}',Because15 = '{txtbecause15.Text}',
                    Because21 = '{txtbecause21.Text}',Because22 = '{txtbecause22.Text}',Because23 = '{txtbecause23.Text}',Because24 = '{txtbecause24.Text}',Because25 = '{txtbecause25.Text}',
                    Result1 = '{btn1}',Result2 = '{btn2}'";
                bool resstep6_5why = LSQL.SQL.Update(SystemInfo.SQL, "A3_Step6_5Why", content2, $"A3ReportNumberID = '{rootcause.A3number}'");
                bool reslist = LSQL.SQL.Update(SystemInfo.SQL, "A3_List", "Step6 = 2", $"ID = '{rootcause.A3number}'");
                if (resstep6 == true && resstep6_5why == true && reslist == true)
                {

                    MessageBox.Show("更新成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Step6_Load(sender, e);
                    btnNext.Visible = true;
                }
                else
                {
                    MessageBox.Show("更新失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }

            }
            else if (A3Step6.Rows.Count == 0 && A3Step6_5Why.Rows.Count > 0)
            {
                //Step6保存语句
                string colunm = "[A3ReportNumberID],[PossibleCauses1],[PossibleCauses2],[PossibleCauses3],[PossibleCauses4],[PossibleCauses5],[PossibleCauses6],[PossibleCauses7],[PossibleCauses8],[PossibleCauses9]," +
                    "[Action1],[Action2],[Action3],[Action4],[Action5],[Action6],[Action7],[Action8],[Action9]," +
                    "[Who1],[Who2],[Who3],[Who4],[Who5],[Who6],[Who7],[Who8],[Who9]," +
                    "[When1],[When2],[When3],[When4],[When5],[When6],[When7],[When8],[When9]," +
                    "[Direct1],[Direct2],[Direct3],[Direct4],[Direct5],[Direct6],[Direct7],[Direct8],[Direct9]," +
                    "[Not1],[Not2],[Not3],[Not4],[Not5],[Not6],[Not7],[Not8],[Not9]";
                string content = $@"'{rootcause.A3number}','{cob1.Text}','{cob2.Text}','{cob3.Text}','{cob4.Text}','{cob5.Text}','{cob6.Text}','{cob7.Text}','{cob8.Text}','{cob9.Text}',
                    '{txtaction1.Text}','{txtaction2.Text}','{txtaction3.Text}','{txtaction4.Text}','{txtaction5.Text}','{txtaction6.Text}','{txtaction7.Text}','{txtaction8.Text}','{txtaction9.Text}',
                    '{txtwho1.Text}','{txtwho2.Text}','{txtwho3.Text}','{txtwho4.Text}','{txtwho5.Text}','{txtwho6.Text}','{txtwho7.Text}','{txtwho8.Text}','{txtwho9.Text}',
                    '{dtwhen1.DateTime}','{dtwhen2.DateTime}','{dtwhen3.DateTime}','{dtwhen4.DateTime}','{dtwhen5.DateTime}','{dtwhen6.DateTime}','{dtwhen7.DateTime}','{dtwhen8.DateTime}','{dtwhen9.DateTime}',
                    '{ckdirect1.Checked}','{ckdirect2.Checked}','{ckdirect3.Checked}','{ckdirect4.Checked}','{ckdirect5.Checked}','{ckdirect6.Checked}','{ckdirect7.Checked}','{ckdirect8.Checked}','{ckdirect9.Checked}',
                    '{cknot1.Checked}','{cknot2.Checked}','{cknot3.Checked}','{cknot4.Checked}','{cknot5.Checked}','{cknot6.Checked}','{cknot7.Checked}','{cknot8.Checked}','{cknot9.Checked}'";
                int res = LSQL.SQL.Insert(SystemInfo.SQL, "A3_Step6", colunm, content);
                //5Why更新语句
                string content2 = $@"DirectCause1 = '{cob21.Text}',DirectCause2 = '{cob22.Text}',
                    Why11 = '{txtwhy11.Text}',Why12 = '{txtwhy12.Text}',Why13 = '{txtwhy13.Text}',Why14 = '{txtwhy14.Text}',Why15 = '{txtwhy15.Text}',
                    Why21 = '{txtwhy21.Text}',Why22 = '{txtwhy22.Text}',Why23 = '{txtwhy23.Text}',Why24 = '{txtwhy24.Text}',Why25 = '{txtwhy25.Text}',
                    Because11 = '{txtbecause11.Text}',Because12 = '{txtbecause12.Text}',Because13 = '{txtbecause13.Text}',Because14 = '{txtbecause14.Text}',Because15 = '{txtbecause15.Text}',
                    Because21 = '{txtbecause21.Text}',Because22 = '{txtbecause22.Text}',Because23 = '{txtbecause23.Text}',Because24 = '{txtbecause24.Text}',Because25 = '{txtbecause25.Text}',
                    Result1 = '{btn1}',Result2 = '{btn2}'";
                bool resstep6_5why = LSQL.SQL.Update(SystemInfo.SQL, "A3_Step6_5Why", content2, $"A3ReportNumberID = '{rootcause.A3number}'");
                if (res == 1 && resstep6_5why == true)
                {
                    bool reslist = LSQL.SQL.Update(SystemInfo.SQL, "A3_List", "Step6 = 2", $"ID = '{rootcause.A3number}'");
                    if (reslist == true)
                    {
                        MessageBox.Show("更新成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Step6_Load(sender, e);
                        btnNext.Visible = true;
                    }
                }
                else
                {
                    MessageBox.Show("更新失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }

            }
            else if (A3Step6.Rows.Count > 0 && A3Step6_5Why.Rows.Count == 0)
            {
                //Step6更新语句
                string content = $@"PossibleCauses1 = '{cob1.Text}',PossibleCauses2 = '{cob2.Text}',PossibleCauses3 = '{cob3.Text}',PossibleCauses4 = '{cob4.Text}',PossibleCauses5 = '{cob5.Text}',PossibleCauses6 = '{cob6.Text}',PossibleCauses7 = '{cob7.Text}',PossibleCauses8 = '{cob8.Text}',PossibleCauses9 = '{cob9.Text}',
                    Action1 = '{txtaction1.Text}',Action2 = '{txtaction2.Text}',Action3 = '{txtaction3.Text}',Action4 = '{txtaction4.Text}',Action5 = '{txtaction5.Text}',Action6 = '{txtaction6.Text}',Action7 = '{txtaction7.Text}',Action8 = '{txtaction8.Text}',Action9 = '{txtaction9.Text}',
                    Who1 = '{txtwho1.Text}',Who2 = '{txtwho2.Text}',Who3 = '{txtwho3.Text}',Who4 = '{txtwho4.Text}',Who5 = '{txtwho5.Text}',Who6 = '{txtwho6.Text}',Who7 = '{txtwho7.Text}',Who8 = '{txtwho8.Text}',Who9 = '{txtwho9.Text}',
                    When1 = '{dtwhen1.DateTime}',When2 = '{dtwhen2.DateTime}',When3 = '{dtwhen3.DateTime}',When4 = '{dtwhen4.DateTime}',When5 = '{dtwhen5.DateTime}',When6 = '{dtwhen6.DateTime}',When7 = '{dtwhen7.DateTime}',When8 = '{dtwhen8.DateTime}',When9 = '{dtwhen9.DateTime}',
                    Direct1 = '{ckdirect1.Checked}',Direct2 = '{ckdirect2.Checked}',Direct3 = '{ckdirect3.Checked}',Direct4 = '{ckdirect4.Checked}',Direct5 = '{ckdirect5.Checked}',Direct6 = '{ckdirect6.Checked}',Direct7 = '{ckdirect7.Checked}',Direct8 = '{ckdirect8.Checked}',Direct9 = '{ckdirect9.Checked}',
                    Not1 = '{cknot1.Checked}',Not2 = '{cknot2.Checked}',Not3 = '{cknot3.Checked}',Not4 = '{cknot4.Checked}',Not5 = '{cknot5.Checked}',Not6 = '{cknot6.Checked}',Not7 = '{cknot7.Checked}',Not8 = '{cknot8.Checked}',Not9 = '{cknot9.Checked}'";
                bool resstep6 = LSQL.SQL.Update(SystemInfo.SQL, "A3_Step6", content, $"A3ReportNumberID = '{rootcause.A3number}'");
                //5Why保存语句
                string colunm2 = "[A3ReportNumberID],[DirectCause1],[DirectCause2]," +
                    "[Why11],[Why12],[Why13],[Why14],[Why15]," +
                    "[Why21],[Why22],[Why23],[Why24],[Why25]," +
                    "[Because11],[Because12],[Because13],[Because14],[Because15]," +
                    "[Because21],[Because22],[Because23],[Because24],[Because25]," +
                    "[Result1],[Result2]";
                string content2 = $@"'{rootcause.A3number}','{cob21.Text}','{cob22.Text}',
                    '{txtwhy11.Text}','{txtwhy12.Text}','{txtwhy13.Text}','{txtwhy14.Text}','{txtwhy15.Text}',
                    '{txtwhy21.Text}','{txtwhy22.Text}','{txtwhy23.Text}','{txtwhy24.Text}','{txtwhy25.Text}',
                    '{txtbecause11.Text}','{txtbecause12.Text}','{txtbecause13.Text}','{txtbecause14.Text}','{txtbecause15.Text}',
                    '{txtbecause21.Text}','{txtbecause22.Text}','{txtbecause23.Text}','{txtbecause24.Text}','{txtbecause25.Text}',
                    '{btn1}','{btn2}'";
                int res2 = LSQL.SQL.Insert(SystemInfo.SQL, "A3_Step6_5Why", colunm2, content2);
                if (resstep6 == true && res2 == 1)
                {
                    bool reslist = LSQL.SQL.Update(SystemInfo.SQL, "A3_List", "Step6 = 2", $"ID = '{rootcause.A3number}'");
                    if (reslist == true)
                    {
                        MessageBox.Show("更新成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Step6_Load(sender, e);
                        btnNext.Visible = true;
                    }
                }
                else
                {
                    MessageBox.Show("更新失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }

            }
            else if(A3Step6.Rows.Count == 0 && A3Step6_5Why.Rows.Count == 0)
            {
                //Step6保存语句
                string colunm = "[A3ReportNumberID],[PossibleCauses1],[PossibleCauses2],[PossibleCauses3],[PossibleCauses4],[PossibleCauses5],[PossibleCauses6],[PossibleCauses7],[PossibleCauses8],[PossibleCauses9]," +
                    "[Action1],[Action2],[Action3],[Action4],[Action5],[Action6],[Action7],[Action8],[Action9]," +
                    "[Who1],[Who2],[Who3],[Who4],[Who5],[Who6],[Who7],[Who8],[Who9]," +
                    "[When1],[When2],[When3],[When4],[When5],[When6],[When7],[When8],[When9]," +
                    "[Direct1],[Direct2],[Direct3],[Direct4],[Direct5],[Direct6],[Direct7],[Direct8],[Direct9]," +
                    "[Not1],[Not2],[Not3],[Not4],[Not5],[Not6],[Not7],[Not8],[Not9]";
                string content = $@"'{rootcause.A3number}','{cob1.Text}','{cob2.Text}','{cob3.Text}','{cob4.Text}','{cob5.Text}','{cob6.Text}','{cob7.Text}','{cob8.Text}','{cob9.Text}',
                    '{txtaction1.Text}','{txtaction2.Text}','{txtaction3.Text}','{txtaction4.Text}','{txtaction5.Text}','{txtaction6.Text}','{txtaction7.Text}','{txtaction8.Text}','{txtaction9.Text}',
                    '{txtwho1.Text}','{txtwho2.Text}','{txtwho3.Text}','{txtwho4.Text}','{txtwho5.Text}','{txtwho6.Text}','{txtwho7.Text}','{txtwho8.Text}','{txtwho9.Text}',
                    '{dtwhen1.DateTime}','{dtwhen2.DateTime}','{dtwhen3.DateTime}','{dtwhen4.DateTime}','{dtwhen5.DateTime}','{dtwhen6.DateTime}','{dtwhen7.DateTime}','{dtwhen8.DateTime}','{dtwhen9.DateTime}',
                    '{ckdirect1.Checked}','{ckdirect2.Checked}','{ckdirect3.Checked}','{ckdirect4.Checked}','{ckdirect5.Checked}','{ckdirect6.Checked}','{ckdirect7.Checked}','{ckdirect8.Checked}','{ckdirect9.Checked}',
                    '{cknot1.Checked}','{cknot2.Checked}','{cknot3.Checked}','{cknot4.Checked}','{cknot5.Checked}','{cknot6.Checked}','{cknot7.Checked}','{cknot8.Checked}','{cknot9.Checked}'";
                int res = LSQL.SQL.Insert(SystemInfo.SQL, "A3_Step6", colunm, content);
                //5Why保存语句
                string colunm2 = "[A3ReportNumberID],[DirectCause1],[DirectCause2]," +
                    "[Why11],[Why12],[Why13],[Why14],[Why15]," +
                    "[Why21],[Why22],[Why23],[Why24],[Why25]," +
                    "[Because11],[Because12],[Because13],[Because14],[Because15]," +
                    "[Because21],[Because22],[Because23],[Because24],[Because25]," +
                    "[Result1],[Result2]";
                string content2 = $@"'{rootcause.A3number}','{cob21.Text}','{cob22.Text}',
                    '{txtwhy11.Text}','{txtwhy12.Text}','{txtwhy13.Text}','{txtwhy14.Text}','{txtwhy15.Text}',
                    '{txtwhy21.Text}','{txtwhy22.Text}','{txtwhy23.Text}','{txtwhy24.Text}','{txtwhy25.Text}',
                    '{txtbecause11.Text}','{txtbecause12.Text}','{txtbecause13.Text}','{txtbecause14.Text}','{txtbecause15.Text}',
                    '{txtbecause21.Text}','{txtbecause22.Text}','{txtbecause23.Text}','{txtbecause24.Text}','{txtbecause25.Text}',
                    '{btn1}','{btn2}'";
                int res2 = LSQL.SQL.Insert(SystemInfo.SQL, "A3_Step6_5Why", colunm2, content2);
                if (res == 1 && res2 == 1)
                {
                    bool reslist = LSQL.SQL.Update(SystemInfo.SQL, "A3_List", "Step6 = 2", $"ID = '{rootcause.A3number}'");
                    if (reslist == true)
                    {
                        MessageBox.Show("保存成功", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Step6_Load(sender, e);
                        btnNext.Visible = true;
                    }
                }
                else
                {
                    MessageBox.Show("保存失败", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }

            }
        }
        private void Rootcause1yes_Click(object sender, EventArgs e)
        {
            btn1 = true;
            Rootcause1yes.Appearance.BackColor = Color.Green;
            Rootcause1yes.Appearance.BorderColor = Color.Transparent;
            Rootcause1no.Appearance.BackColor = Color.FromArgb(234, 234, 234);
        }
        private void Rootcause1no_Click(object sender, EventArgs e)
        {
            btn1 = false;
            Rootcause1no.Appearance.BackColor = Color.Red;
            Rootcause1no.Appearance.BorderColor = Color.Transparent;
            Rootcause1yes.Appearance.BackColor = Color.FromArgb(234, 234, 234);
        }

        private void Rootcause2yes_Click(object sender, EventArgs e)
        {
            btn2 = true;
            Rootcause2yes.Appearance.BackColor = Color.Green;
            Rootcause2yes.Appearance.BorderColor= Color.Transparent;
            Rootcause2no.Appearance.BackColor = Color.FromArgb(234, 234, 234);
        }

        private void Rootcause2no_Click(object sender, EventArgs e)
        {
            btn2 = false;
            Rootcause2no.Appearance.BackColor = Color.Red;
            Rootcause2no.Appearance.BorderColor =Color.Transparent;
            Rootcause2yes.Appearance.BackColor = Color.FromArgb(234, 234, 234);
        }
        // 为每一对控件创建一个方法来处理互斥逻辑
        private void SetMutualExclusive(CheckEdit firstCheck, CheckEdit secondCheck)
        {
            if (firstCheck.Checked)
            {
                secondCheck.Checked = false; // 如果第一个选中，则将第二个设为未选中
            }
        }

        private void ckdirect_CheckedChanged(object sender, EventArgs e)
        {
            CheckEdit senderCheck = sender as CheckEdit;

            if (senderCheck == ckdirect1)
            {
                SetMutualExclusive(ckdirect1, cknot1);
            }
            else if (senderCheck == cknot1)
            {
                SetMutualExclusive(cknot1, ckdirect1);
            }

            if (senderCheck == ckdirect2)
            {
                SetMutualExclusive(ckdirect2, cknot2);
            }
            else if (senderCheck == cknot2)
            {
                SetMutualExclusive(cknot2, ckdirect2);
            }

            if (senderCheck == ckdirect3)
            {
                SetMutualExclusive(ckdirect3, cknot3);
            }
            else if (senderCheck == cknot3)
            {
                SetMutualExclusive(cknot3, ckdirect3);
            }

            if (senderCheck == ckdirect4)
            {
                SetMutualExclusive(ckdirect4, cknot4);
            }
            else if (senderCheck == cknot4)
            {
                SetMutualExclusive(cknot4, ckdirect4);
            }

            if (senderCheck == ckdirect5)
            {
                SetMutualExclusive(ckdirect5, cknot5);
            }
            else if (senderCheck == cknot5)
            {
                SetMutualExclusive(cknot5, ckdirect5);
            }

            if (senderCheck == ckdirect6)
            {
                SetMutualExclusive(ckdirect6, cknot6);
            }
            else if (senderCheck == cknot6)
            {
                SetMutualExclusive(cknot6, ckdirect6);
            }

            if (senderCheck == ckdirect7)
            {
                SetMutualExclusive(ckdirect7, cknot7);
            }
            else if (senderCheck == cknot7)
            {
                SetMutualExclusive(cknot7, ckdirect7);
            }

            if (senderCheck == ckdirect8)
            {
                SetMutualExclusive(ckdirect8, cknot8);
            }
            else if (senderCheck == cknot8)
            {
                SetMutualExclusive(cknot8, ckdirect8);
            }

            if (senderCheck == ckdirect9)
            {
                SetMutualExclusive(ckdirect9, cknot9);
            }
            else if (senderCheck == cknot9)
            {
                SetMutualExclusive(cknot9, ckdirect9);
            }
        }

        private void btnClosed_Click(object sender, EventArgs e)
        {
            // 弹出确认对话框，询问是否关闭
            DialogResult result = MessageBox.Show("是否确定关闭？", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.Yes)
            {
                // 用户选择“是”，执行关闭操作
                this.Close(); // 关闭当前窗体
            }
            else
            {
                // 用户选择“否”，返回，不做任何操作
                return;
            }
        }
        //点击图片跳转功能
        private void picstep1_Click(object sender, EventArgs e)
        {
            if (step1 == 4)
            {
                return;
            }
            else
            {
                Step1 frm = new Step1();
                this.Close();
                frm.Show();
            }
        }

        private void picstep2_Click(object sender, EventArgs e)
        {
            if (step2 == 4)
            {
                return;
            }
            else
            {
                Step2 frm = new Step2();
                this.Close();
                frm.Show();
            }
        }

        private void picstep3_Click(object sender, EventArgs e)
        {
            if (step3 == 4)
            {
                return;
            }
            else
            {
                Step3 frm = new Step3();
                this.Close();
                frm.Show();
            }
        }
        private void picstep4_Click(object sender, EventArgs e)
        {
            if (step4 == 4)
            {
                return;
            }
            else
            {
                Step4 frm = new Step4();
                this.Close();
                frm.Show();
            }
        }

        private void picstep5_Click(object sender, EventArgs e)
        {
            if (step5 == 4)
            {
                return;
            }
            else
            {
                Step5 frm = new Step5();
                this.Close();
                frm.Show();
            }
        }

        private void picstep6_Click(object sender, EventArgs e)
        {
            if (step6 == 4)
            {
                return;
            }
            else
            {
                Step6 frm = new Step6();
                this.Close();
                frm.Show();
            }
        }

        private void picstep7_Click(object sender, EventArgs e)
        {
            if (step7 == 4)
            {
                return;
            }
            else
            {
                Step7 frm = new Step7();
                this.Close();
                frm.Show();
            }
        }

        private void picstep8_Click(object sender, EventArgs e)
        {
            if (step8 == 4)
            {
                return;
            }
            else
            {
                Step8 frm = new Step8();
                this.Close();
                frm.Show();
            }
        }

        private void picstep9_Click(object sender, EventArgs e)
        {
            if (step9 == 4)
            {
                return;
            }
            else
            {
                Step9 frm = new Step9();
                this.Close();
                frm.Show();
            }
        }
    }
}